// VBConversions Note: VB project level imports
using System.Collections.Generic;
using System;
using System.Linq;
using System.Drawing;
using System.Diagnostics;
using Microsoft.VisualBasic;
using System.Xml.Linq;
using Microsoft.VisualBasic.Compatibility;
using System.Windows.Forms;
using System.Collections;
using System.Data;
// End of VB project level imports

using System.Data.Sql;
using System.Data.SqlClient;

namespace 喷码数据生成工具
{
	public class SqlDataBase
	{
		SqlConnection mConnction = new SqlConnection();
		SqlCommand m_SqlCommand;
public SqlConnection getSqlConnection
		{
			get
			{
				return mConnction;
			}
		}
		public void ConnectDataBase(string IP, int Port, string UserName, string Pwd, string DataBase)
		{
			try
			{
				mConnction.ConnectionString = "server=" + IP + ";uid=" + UserName + ";pwd=" + Pwd + ";database=" + DataBase;
				mConnction.Open();
				if (m_SqlCommand == null)
				{
					m_SqlCommand = new SqlCommand();
				}
				m_SqlCommand.Connection = mConnction;
			}
			catch (Exception ex)
			{
				throw (new Exception(ex.Message));
			}
		}
		public void Close()
		{
			mConnction.Close();
		}
		public void Dispose()
		{
			mConnction.Dispose();
		}
public ConnectionState ConnectionState
		{
			get
			{
				return mConnction.State;
			}
		}
		public DataSet Search(string TableName, string SqlStr)
		{
			try
			{
				SqlDataAdapter Adpter = default(SqlDataAdapter);
				DataSet rds = new DataSet();
				m_SqlCommand = new SqlCommand(SqlStr, mConnction);
				Adpter = new SqlDataAdapter(m_SqlCommand);
				Adpter.Fill(rds, TableName);
				return rds;
			}
			catch (Exception ex)
			{
				throw (new Exception(ex.Message));
			}
		}
		public DataSet Search(string TableName)
		{
			try
			{
				SqlDataAdapter Adpter = default(SqlDataAdapter);
				DataSet rds = new DataSet();
				m_SqlCommand = new SqlCommand("Select * from " + TableName, mConnction);
				Adpter = new SqlDataAdapter(m_SqlCommand);
				Adpter.Fill(rds, TableName);
				return rds;
			}
			catch (Exception ex)
			{
				throw (new Exception(ex.Message));
			}
		}
	}
	
}
